package com.mxpio.erp.common.service.impl;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.mxpio.erp.common.enums.OrderStatusEnums.CloseStatus;
import com.mxpio.erp.common.jpa.model.OrderLine;
import com.mxpio.erp.common.jpa.model.OrderLineKey;
import com.mxpio.erp.common.service.OrderLineService;
import com.mxpioframework.common.vo.Result;
import com.mxpioframework.jpa.JpaUtil;
import com.mxpioframework.system.service.impl.BaseServiceImpl;

@Service
public class OrderLineServiceImpl extends BaseServiceImpl<OrderLine> implements OrderLineService {

	@Override
	@Transactional(readOnly = false)
	public Result<? extends OrderLine> updateCloseStatus(Class<? extends OrderLine> clazz, String ids, CloseStatus closeStatus) {
		String[] id = ids.split(",");
        for(String key : id){
            String[] pk = key.split(":");
            OrderLineKey lineKey = new OrderLineKey();
            lineKey.setBizNo(pk[0]);
            lineKey.setLineNo(pk[1]);
            OrderLine bizOrderLine = JpaUtil.getOne(clazz, lineKey);
            bizOrderLine.setCloseStatus(closeStatus.getStatusCode());
            this.update(bizOrderLine);
        }
        return Result.OK();
	}

}
